-- 通用描述tips

local newDescTipsView = class("newDescTipsView",function()
    return ccui.Layout:create()
end)

function newDescTipsView:ctor()
    local function createModuleNode(uiPath, uiNodeName, parent)
        local node = cc.uiloader:load( uiPath )
        local moduleNode = node:getChildByName( uiNodeName )
        moduleNode:retain()
        moduleNode:removeFromParent()
        parent:addChild( moduleNode )
        moduleNode:release()
        return moduleNode
    end
    self.mUINode = createModuleNode( Res.Tips_Desc, "Panel", self )
    self:setContentSize( self.mUINode:getContentSize() )
    ccui.Helper:doLayout( self.mUINode )
    
    self._text = self.mUINode:getChildByName( "text" ) 
    local sizeWidth, sizeHeight = self._text:getContentSize2()
    self._sizeWidth = sizeWidth
    local panelContetsizeWidth, panelContetsizeHeight = self.mUINode:getContentSize2()
    self._panelWidth = panelContetsizeWidth
end

function newDescTipsView:setContentText( str )
    self._text:setVisible(true)
    if self._extendParents then
        self._extendParents:removeAllChildren()
        self._extendParents:setVisible(false)
    end
    local panelContetsizeWidth, panelContetsizeHeight = self.mUINode:getContentSize2()
    local sizeWidth, sizeHeight = self._text:getContentSize2()
    self._text:getVirtualRenderer():setDimensions( sizeWidth, 0 )
    self._text:setString( str and str or "" )
    local afterSize = self._text:getVirtualRendererSize()
    local descSubHeight = sizeHeight - afterSize.height

    self.mUINode:setContentSize( cc.size( panelContetsizeWidth, panelContetsizeHeight - descSubHeight * self._text:getScaleY() ) )
    self:setContentSize( cc.size( panelContetsizeWidth, panelContetsizeHeight - descSubHeight * self._text:getScaleY() ) )
    self._text:setContentSize( cc.size( sizeWidth, sizeHeight - descSubHeight ) )

    ccui.Helper:doLayout( self.mUINode )
end


function newDescTipsView:setTextColor(color)
    self._text:setColor(color)
end
-- 扩充文本显示
--[[
    {{}},
]]
function newDescTipsView:setExtendTexts(configs, offsetY)
    if not self._extendParents then
        self._extendParents = ccui.Widget:create()
        self.mUINode:addChild(self._extendParents)
    end
    self._text:setVisible(false)
    self._extendParents:removeAllChildren()
    self._extendParents:setVisible(true)
   
    local posY = 0
    local posX = 0
    if not offsetY then
        offsetY = 5
    end
    local parentNode = cc.Node:create()

    local ttfConfig = {}
    ttfConfig.fontFilePath = Res.font
    -- ttfConfig.fontSize = 18
    	
    for k ,v in pairs(configs) do
        if v.fontSize then
            ttfConfig.fontSize = v.fontSize
        else
            ttfConfig.fontSize = 18
        end
        local textNode = cc.Label:createWithTTF(ttfConfig, v.text, cc.TEXT_ALIGNMENT_LEFT)
        textNode:setAnchorPoint(cc.p(0, 1))
        textNode:setDimensions( self._sizeWidth, 0 )
        if v.color then
            textNode:setColor(v.color)
        end
        self._extendParents:addChild(textNode)
        local size = textNode:getContentSize()
        textNode:setPosition(cc.p(0, posY))
        posY = posY - size.height - offsetY
    end
    local exHeight = - posY - offsetY
    self._extendParents:setPosition( 12, exHeight + 9)
    local totalHeight = exHeight + 20

    self.mUINode:setContentSize( cc.size(  self._panelWidth, totalHeight ) )
    self:setContentSize( cc.size(  self._panelWidth, totalHeight) )
    ccui.Helper:doLayout( self.mUINode )
end

return newDescTipsView
